import csv
from GUI_KDT.common.common_utils import CommonUtils
from GUI_KDT.config.config import keyword
import os

from GUI_KDT.utils.excel_tools import ReadExcel


class Controller:

    def __init__(self):
        self.con = CommonUtils()
        self.excel = ReadExcel()

    def run(self):
        # 动态读取所有表名
        sheet_names = self.excel.allnames
        pass
        for i in range(len(sheet_names)):
            sheet_index = i
            sheet_name = sheet_names[i]
            # 获取指定表所有行
            rows_num = self.excel.get_nrows(sheet_name)
            # 如果行数为0就跳过
            if rows_num == 0:
                continue
            # 循环读取每一行的case
            for i in range(1, rows_num):
                row_data = self.excel.get_data_by_name(sheet_name, i)
                case_list = row_data[2].split("\n")
                for i in case_list:
                    i1 = i.split("\n")
                    res_list = i1[0].split("||")
                    action_Ch = res_list.pop(0)
                    action_En = keyword[action_Ch]
                    getattr(self.con, action_En)(*res_list)


if __name__ == '__main__':
    con = Controller()
    con.run()
